/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * KPrikaz.java
 *
 * Created on 09.03.2010., 23.55.35
 */

package KLforme;
import javax.swing.table.DefaultTableModel;
import klijent.KlijentVeza;
import model.Paket;
import model.Radnik;

/**
 *
 * @author Dejan
 */
public class KPrikaz extends javax.swing.JFrame {
DefaultTableModel model;
private KlijentVeza k;
    /** Creates new form KPrikaz */
    public KPrikaz(KlijentVeza k) {
        this.k=k;
        initComponents();
        inicijalizujTabelu();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jbPrikazi = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jbPrikazi.setText("Prikazi sve!");
        jbPrikazi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPrikaziActionPerformed(evt);
            }
        });

        jLabel1.setText("PREGLED");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(166, Short.MAX_VALUE)
                .addComponent(jbPrikazi)
                .addGap(181, 181, 181))
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbPrikazi))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbPrikaziActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPrikaziActionPerformed
        k.posalji(new Paket("zahtev liste radnika"));
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {


               // new KLogin().setVisible(true);
               while(true){
                  if(!(k.getRadnici()==null) ){

                      popuniTabelu();
                      k.setRadnici(null);
                      break;
                  }


               }
            }
        });


        
    }//GEN-LAST:event_jbPrikaziActionPerformed
private void inicijalizujTabelu() {
        model = new DefaultTableModel(
        new Object [][] {
        },
        new String [] { "sifra","Ime", "prezime", "Adresa"
        }
        );
        jTable1.setModel(model);
    }

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbPrikazi;
    // End of variables declaration//GEN-END:variables

    public void popuniTabelu(){
    inicijalizujTabelu();
    for(Radnik r : k.getRadnici())
        {
            model.addRow(new String[] {r.getSifra(), r.getIme(),r.getIme(), r.getAdresa()});
        }

    }

}
